
function szukaj() {
    var shopname = $("#shopname").val();
    var id = $("#szukajka").val();
    $("#results").children(".list-group").html("");
    var data = {category: id};
    $.ajax({
        type: "POST",
        url: "/" + shopname + "/ajax/autocomplete",
        dataType: "json",
        data: data,
        success: function(json) {
            if (json !== false)
            {
                $("#results").children(".list-group").html("");
                if (json !== null) {
                    $.each(json, function(index, value) {
                        $("#results").children(".list-group").html($("#results").children(".list-group").html() + "<a name=\"" + value["ProductID"] + "\" href=\"#\" class=\"list-group-item small\" onclick=\"dodaj($(this))\">" + value["Name"] + "</a>");

                    });
                }
                // console.log(json);
            }
            else {
                $("#results").children(".list-group").html("<a href=\"#\" class=\"list-group-item\">brak danych</a>");
            }
        },
    });
}
function searchCustomer() {
     var shopname = $("#shopname").val();
    var id = $("#szukajka").val();
    $("#results").children(".list-group").html("");
    var data = {name: id};
    $.ajax({
        type: "POST",
        url: "/" + shopname + "/ajax/searchCustomer",
        dataType: "json",
        data: data,
        success: function(json) {
            if (json !== false)
            {
                $("#results").children(".list-group").html("");
                if (json !== null) {
                    $.each(json, function(index, value) {
                        var url="/"+shopname+"/ShopAdmin_Customer?id="+value["CustomerID"];
                        $("#results").children(".list-group").html($("#results").children(".list-group").html() + "<a href=\"" + url + "\" class=\"list-group-item small\" >" + value["PersonID"]["Name"] + " "+value["PersonID"]["Surname"]+ "</a>");

                    });
                }
                // console.log(json);
            }
            else {
                $("#results").children(".list-group").html("<a href=\"#\" class=\"list-group-item\">brak danych</a>");
            }
        },
    });
}
function search(){
     var shopname = $("#shopname").val();
    var id = $("#szukajka").val();
    $("#results").children(".list-group").html("");
    var data = {category: id};
    $.ajax({
        type: "POST",
        url: "/" + shopname + "/ajax/autocomplete",
        dataType: "json",
        data: data,
        success: function(json) {
            if (json !== false)
            {
                $("#results").children(".list-group").html("");
                if (json !== null) {
                    $.each(json, function(index, value) {
                        var url="/"+shopname+"/sp/"+value["URL"];
                        $("#results").children(".list-group").html($("#results").children(".list-group").html() + "<a name=\"" + value["ProductID"] + "\" href=\"" + url + "\" class=\"list-group-item small\" >" + value["Name"] + "</a>");

                    });
                }
                // console.log(json);
            }
            else {
                $("#results").children(".list-group").html("<a href=\"#\" class=\"list-group-item\">brak danych</a>");
            }
        },
        error: function(data) {
            console.log(data.responseText);
        }
    });
}
$(document).click(function() {
    $("#results").children(".list-group").html("");
});
var counter = 1;

$('#addRow').on('click', function() {


    counter++;
});